import {getListData,searchData,updateMenu} from '../apis/menu.js'
import {message} from 'antd'
export default {
    state:{
        menuList:[]
    },
    effects:{
        *menuListInit ({payload},{call,put}){
            const res=yield call(getListData,payload)
            // console.log(res.menus);
            yield put({
                type:'initMenuList',
                payload:res.menus
            })
        },
        *initSearch({payload},{call,put}){
            const res=yield call(searchData,payload)
            // console.log(res.menus);
            yield put({
                type:'searchInit',
                payload:res.menus
            })
        },
        *updateMenuOne({payload},{call,put}){
            const result=yield call(updateMenu,payload)
            console.log(result);
            if(result.meta.status==200){
                message.success('修改成功')
            }
            const res=yield call(getListData,payload)
            yield put({
                type:'initMenuList',
                payload:res.menus
            })
        }
    },
    reducers:{
        initMenuList(state,action){
            state.menuList=action.payload
        },
        searchInit(state,action){
            state.menuList=action.payload
        }
    }
}